84a3b7ef0d7246a5741ac014d292eb022bd0b0ce
3 * Form to edit user preferences.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * We're now using the HTMLForm object with some customisation to generate the
25 * Preferences form. This object handles generic submission, CSRF protection,
26 * layout and other logic in a reusable manner. We subclass it as a PreferencesForm
27 * to make some minor customisations.
29 * In order to generate the form, the HTMLForm object needs an array structure
30 * detailing the form fields available, and that's what this class is for. Each
31 * element of the array is a basic property-list, including the type of field,
32 * the label it is to be given in the form, callbacks for validation and
33 * 'filtering', and other pertinent information. Note that the 'default' field
34 * is named for generic forms, and does not represent the preference's default
35 * (which is stored in $wgDefaultUserOptions), but the default for the form
36 * field, which should be whatever the user has set for that preference. There
37 * is no need to override it unless you have some special storage logic (for
38 * instance, those not presently stored as options, but which are best set from
39 * the user preferences view).
41 * Field types are implemented as subclasses of the generic HTMLFormField
42 * object, and typically implement at least getInputHTML, which generates the
43 * HTML for the input field to be placed in the table.
45 * Once fields have been retrieved and validated, submission logic is handed
46 * over to the tryUISubmit static method of this class.
49 static $defaultPreferences = null;
50 static $saveFilters = array(
51 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ),
52 'cols' => array( 'Preferences', 'filterIntval' ),
53 'rows' => array( 'Preferences', 'filterIntval' ),
54 'rclimit' => array( 'Preferences', 'filterIntval' ),
55 'wllimit' => array( 'Preferences', 'filterIntval' ),
56 'searchlimit' => array( 'Preferences', 'filterIntval' ),
59 // Stuff that shouldn't be saved as a preference.
60 private static $saveBlacklist = array(
68 * @param $context IContextSource
71 static function getPreferences( $user, IContextSource
$context ) {
72 if ( self
::$defaultPreferences ) {
73 return self
::$defaultPreferences;
76 $defaultPreferences = array();
78 self
::profilePreferences( $user, $context, $defaultPreferences );
79 self
::skinPreferences( $user, $context, $defaultPreferences );
80 self
::filesPreferences( $user, $context, $defaultPreferences );
81 self
::datetimePreferences( $user, $context, $defaultPreferences );
82 self
::renderingPreferences( $user, $context, $defaultPreferences );
83 self
::editingPreferences( $user, $context, $defaultPreferences );
84 self
::rcPreferences( $user, $context, $defaultPreferences );
85 self
::watchlistPreferences( $user, $context, $defaultPreferences );
86 self
::searchPreferences( $user, $context, $defaultPreferences );
87 self
::miscPreferences( $user, $context, $defaultPreferences );
89 wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) );
91 ## Remove preferences that wikis don't want to use
92 global $wgHiddenPrefs;
93 foreach ( $wgHiddenPrefs as $pref ) {
94 if ( isset( $defaultPreferences[$pref] ) ) {
95 unset( $defaultPreferences[$pref] );
99 ## Make sure that form fields have their parent set. See bug 41337.
100 $dummyForm = new HTMLForm( array(), $context );
102 $disable = !$user->isAllowed( 'editmyoptions' );
104 ## Prod in defaults from the user
105 foreach ( $defaultPreferences as $name => &$info ) {
106 $prefFromUser = self
::getOptionFromUser( $name, $info, $user );
107 if ( $disable && !in_array( $name, self
::$saveBlacklist ) ) {
108 $info['disabled'] = 'disabled';
110 $field = HTMLForm
::loadInputFromParameters( $name, $info ); // For validation
111 $field->mParent
= $dummyForm;
112 $defaultOptions = User
::getDefaultOptions();
113 $globalDefault = isset( $defaultOptions[$name] )
114 ?
$defaultOptions[$name]
117 // If it validates, set it as the default
118 if ( isset( $info['default'] ) ) {
119 // Already set, no problem
121 } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing
122 $field->validate( $prefFromUser, $user->getOptions() ) === true ) {
123 $info['default'] = $prefFromUser;
124 } elseif ( $field->validate( $globalDefault, $user->getOptions() ) === true ) {
125 $info['default'] = $globalDefault;
127 throw new MWException( "Global default '$globalDefault' is invalid for field $name" );
131 self
::$defaultPreferences = $defaultPreferences;
133 return $defaultPreferences;
137 * Pull option from a user account. Handles stuff like array-type preferences.
142 * @return array|String
144 static function getOptionFromUser( $name, $info, $user ) {
145 $val = $user->getOption( $name );
147 // Handling for multiselect preferences
148 if ( ( isset( $info['type'] ) && $info['type'] == 'multiselect' ) ||
149 ( isset( $info['class'] ) && $info['class'] == 'HTMLMultiSelectField' ) ) {
150 $options = HTMLFormField
::flattenOptions( $info['options'] );
151 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
154 foreach ( $options as $value ) {
155 if ( $user->getOption( "$prefix$value" ) ) {
161 // Handling for checkmatrix preferences
162 if ( ( isset( $info['type'] ) && $info['type'] == 'checkmatrix' ) ||
163 ( isset( $info['class'] ) && $info['class'] == 'HTMLCheckMatrix' ) ) {
164 $columns = HTMLFormField
::flattenOptions( $info['columns'] );
165 $rows = HTMLFormField
::flattenOptions( $info['rows'] );
166 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $name;
169 foreach ( $columns as $column ) {
170 foreach ( $rows as $row ) {
171 if ( $user->getOption( "$prefix$column-$row" ) ) {
172 $val[] = "$column-$row";
183 * @param $context IContextSource
184 * @param $defaultPreferences
187 static function profilePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
188 global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode,
189 $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars,
190 $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication,
191 $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress,
194 // retrieving user name for GENDER and misc.
195 $userName = $user->getName();
197 ## User info #####################################
199 $defaultPreferences['username'] = array(
201 'label-message' => array( 'username', $userName ),
202 'default' => $userName,
203 'section' => 'personal/info',
206 $defaultPreferences['userid'] = array(
208 'label-message' => array( 'uid', $userName ),
209 'default' => $user->getId(),
210 'section' => 'personal/info',
213 # Get groups to which the user belongs
214 $userEffectiveGroups = $user->getEffectiveGroups();
215 $userGroups = $userMembers = array();
216 foreach ( $userEffectiveGroups as $ueg ) {
218 // Skip the default * group, seems useless here
221 $groupName = User
::getGroupName( $ueg );
222 $userGroups[] = User
::makeGroupLinkHTML( $ueg, $groupName );
224 $memberName = User
::getGroupMember( $ueg, $userName );
225 $userMembers[] = User
::makeGroupLinkHTML( $ueg, $memberName );
227 asort( $userGroups );
228 asort( $userMembers );
230 $lang = $context->getLanguage();
232 $defaultPreferences['usergroups'] = array(
234 'label' => $context->msg( 'prefs-memberingroups' )->numParams(
235 count( $userGroups ) )->params( $userName )->parse(),
236 'default' => $context->msg( 'prefs-memberingroups-type',
237 $lang->commaList( $userGroups ),
238 $lang->commaList( $userMembers )
241 'section' => 'personal/info',
244 $editCount = Linker
::link( SpecialPage
::getTitleFor( "Contributions", $userName ),
245 $lang->formatNum( $user->getEditCount() ) );
247 $defaultPreferences['editcount'] = array(
250 'label-message' => 'prefs-edits',
251 'default' => $editCount,
252 'section' => 'personal/info',
255 if ( $user->getRegistration() ) {
256 $displayUser = $context->getUser();
257 $userRegistration = $user->getRegistration();
258 $defaultPreferences['registrationdate'] = array(
260 'label-message' => 'prefs-registration',
261 'default' => $context->msg(
262 'prefs-registration-date-time',
263 $lang->userTimeAndDate( $userRegistration, $displayUser ),
264 $lang->userDate( $userRegistration, $displayUser ),
265 $lang->userTime( $userRegistration, $displayUser )
267 'section' => 'personal/info',
271 $canViewPrivateInfo = $user->isAllowed( 'viewmyprivateinfo' );
272 $canEditPrivateInfo = $user->isAllowed( 'editmyprivateinfo' );
274 // Actually changeable stuff
275 $defaultPreferences['realname'] = array(
276 // (not really "private", but still shouldn't be edited without permission)
277 'type' => $canEditPrivateInfo && $wgAuth->allowPropChange( 'realname' ) ?
'text' : 'info',
278 'default' => $user->getRealName(),
279 'section' => 'personal/info',
280 'label-message' => 'yourrealname',
281 'help-message' => 'prefs-help-realname',
284 if ( $canEditPrivateInfo && $wgAuth->allowPasswordChange() ) {
285 $link = Linker
::link( SpecialPage
::getTitleFor( 'ChangePassword' ),
286 $context->msg( 'prefs-resetpass' )->escaped(), array(),
287 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText() ) );
289 $defaultPreferences['password'] = array(
293 'label-message' => 'yourpassword',
294 'section' => 'personal/info',
297 if ( $wgCookieExpiration > 0 ) {
298 $defaultPreferences['rememberpassword'] = array(
300 'label' => $context->msg( 'tog-rememberpassword' )->numParams(
301 ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )->text(),
302 'section' => 'personal/info',
305 // Only show preferhttps if secure login is turned on
306 if ( $wgSecureLogin && wfCanIPUseHTTPS( $context->getRequest()->getIP() ) ) {
307 $defaultPreferences['prefershttps'] = array(
309 'label-message' => 'tog-prefershttps',
310 'section' => 'personal/info'
315 $languages = Language
::fetchLanguageNames( null, 'mw' );
316 if ( !array_key_exists( $wgLanguageCode, $languages ) ) {
317 $languages[$wgLanguageCode] = $wgLanguageCode;
322 foreach ( $languages as $code => $name ) {
323 $display = wfBCP47( $code ) . ' - ' . $name;
324 $options[$display] = $code;
326 $defaultPreferences['language'] = array(
328 'section' => 'personal/i18n',
329 'options' => $options,
330 'label-message' => 'yourlanguage',
333 $defaultPreferences['gender'] = array(
335 'section' => 'personal/i18n',
337 $context->msg( 'gender-male' )->text() => 'male',
338 $context->msg( 'gender-female' )->text() => 'female',
339 $context->msg( 'gender-unknown' )->text() => 'unknown',
341 'label-message' => 'yourgender',
342 'help-message' => 'prefs-help-gender',
345 // see if there are multiple language variants to choose from
346 if ( !$wgDisableLangConversion ) {
347 foreach ( LanguageConverter
::$languagesWithVariants as $langCode ) {
348 if ( $langCode == $wgContLang->getCode() ) {
349 $variants = $wgContLang->getVariants();
351 if ( count( $variants ) <= 1 ) {
355 $variantArray = array();
356 foreach ( $variants as $v ) {
357 $v = str_replace( '_', '-', strtolower( $v ) );
358 $variantArray[$v] = $lang->getVariantname( $v, false );
362 foreach ( $variantArray as $code => $name ) {
363 $display = wfBCP47( $code ) . ' - ' . $name;
364 $options[$display] = $code;
367 $defaultPreferences['variant'] = array(
368 'label-message' => 'yourvariant',
370 'options' => $options,
371 'section' => 'personal/i18n',
372 'help-message' => 'prefs-help-variant',
375 if ( !$wgDisableTitleConversion ) {
376 $defaultPreferences['noconvertlink'] = array(
378 'section' => 'personal/i18n',
379 'label-message' => 'tog-noconvertlink',
383 $defaultPreferences["variant-$langCode"] = array(
390 // show a preview of the old signature first
391 $oldsigWikiText = $wgParser->preSaveTransform( "~~~", $context->getTitle(), $user, ParserOptions
::newFromContext( $context ) );
392 $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true );
393 $defaultPreferences['oldsig'] = array(
396 'label-message' => 'tog-oldsig',
397 'default' => $oldsigHTML,
398 'section' => 'personal/signature',
400 $defaultPreferences['nickname'] = array(
401 'type' => $wgAuth->allowPropChange( 'nickname' ) ?
'text' : 'info',
402 'maxlength' => $wgMaxSigChars,
403 'label-message' => 'yournick',
404 'validation-callback' => array( 'Preferences', 'validateSignature' ),
405 'section' => 'personal/signature',
406 'filter-callback' => array( 'Preferences', 'cleanSignature' ),
408 $defaultPreferences['fancysig'] = array(
410 'label-message' => 'tog-fancysig',
411 'help-message' => 'prefs-help-signature', // show general help about signature at the bottom of the section
412 'section' => 'personal/signature'
417 if ( $wgEnableEmail ) {
418 if ( $canViewPrivateInfo ) {
419 $helpMessages[] = $wgEmailConfirmToEdit
420 ?
'prefs-help-email-required'
421 : 'prefs-help-email';
423 if ( $wgEnableUserEmail ) {
424 // additional messages when users can send email to each other
425 $helpMessages[] = 'prefs-help-email-others';
428 $emailAddress = $user->getEmail() ?
htmlspecialchars( $user->getEmail() ) : '';
429 if ( $canEditPrivateInfo && $wgAuth->allowPropChange( 'emailaddress' ) ) {
430 $link = Linker
::link(
431 SpecialPage
::getTitleFor( 'ChangeEmail' ),
432 $context->msg( $user->getEmail() ?
'prefs-changeemail' : 'prefs-setemail' )->escaped(),
434 array( 'returnto' => SpecialPage
::getTitleFor( 'Preferences' )->getPrefixedText() ) );
436 $emailAddress .= $emailAddress == '' ?
$link : (
437 $context->msg( 'word-separator' )->plain()
438 . $context->msg( 'parentheses' )->rawParams( $link )->plain()
442 $defaultPreferences['emailaddress'] = array(
445 'default' => $emailAddress,
446 'label-message' => 'youremail',
447 'section' => 'personal/email',
448 'help-messages' => $helpMessages,
449 # 'cssclass' chosen below
453 $disableEmailPrefs = false;
455 if ( $wgEmailAuthentication ) {
456 $emailauthenticationclass = 'mw-email-not-authenticated';
457 if ( $user->getEmail() ) {
458 if ( $user->getEmailAuthenticationTimestamp() ) {
459 // date and time are separate parameters to facilitate localisation.
460 // $time is kept for backward compat reasons.
461 // 'emailauthenticated' is also used in SpecialConfirmemail.php
462 $displayUser = $context->getUser();
463 $emailTimestamp = $user->getEmailAuthenticationTimestamp();
464 $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser );
465 $d = $lang->userDate( $emailTimestamp, $displayUser );
466 $t = $lang->userTime( $emailTimestamp, $displayUser );
467 $emailauthenticated = $context->msg( 'emailauthenticated',
468 $time, $d, $t )->parse() . '<br />';
469 $disableEmailPrefs = false;
470 $emailauthenticationclass = 'mw-email-authenticated';
472 $disableEmailPrefs = true;
473 $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '<br />' .
475 SpecialPage
::getTitleFor( 'Confirmemail' ),
476 $context->msg( 'emailconfirmlink' )->escaped()
478 $emailauthenticationclass = "mw-email-not-authenticated";
481 $disableEmailPrefs = true;
482 $emailauthenticated = $context->msg( 'noemailprefs' )->escaped();
483 $emailauthenticationclass = 'mw-email-none';
486 if ( $canViewPrivateInfo ) {
487 $defaultPreferences['emailauthentication'] = array(
490 'section' => 'personal/email',
491 'label-message' => 'prefs-emailconfirm-label',
492 'default' => $emailauthenticated,
493 # Apply the same CSS class used on the input to the message:
494 'cssclass' => $emailauthenticationclass,
496 $defaultPreferences['emailaddress']['cssclass'] = $emailauthenticationclass;
500 if ( $wgEnableUserEmail && $user->isAllowed( 'sendemail' ) ) {
501 $defaultPreferences['disablemail'] = array(
504 'section' => 'personal/email',
505 'label-message' => 'allowemail',
506 'disabled' => $disableEmailPrefs,
508 $defaultPreferences['ccmeonemails'] = array(
510 'section' => 'personal/email',
511 'label-message' => 'tog-ccmeonemails',
512 'disabled' => $disableEmailPrefs,
516 if ( $wgEnotifWatchlist ) {
517 $defaultPreferences['enotifwatchlistpages'] = array(
519 'section' => 'personal/email',
520 'label-message' => 'tog-enotifwatchlistpages',
521 'disabled' => $disableEmailPrefs,
524 if ( $wgEnotifUserTalk ) {
525 $defaultPreferences['enotifusertalkpages'] = array(
527 'section' => 'personal/email',
528 'label-message' => 'tog-enotifusertalkpages',
529 'disabled' => $disableEmailPrefs,
532 if ( $wgEnotifUserTalk ||
$wgEnotifWatchlist ) {
533 $defaultPreferences['enotifminoredits'] = array(
535 'section' => 'personal/email',
536 'label-message' => 'tog-enotifminoredits',
537 'disabled' => $disableEmailPrefs,
540 if ( $wgEnotifRevealEditorAddress ) {
541 $defaultPreferences['enotifrevealaddr'] = array(
543 'section' => 'personal/email',
544 'label-message' => 'tog-enotifrevealaddr',
545 'disabled' => $disableEmailPrefs,
554 * @param $context IContextSource
555 * @param $defaultPreferences
558 static function skinPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
559 ## Skin #####################################
560 global $wgAllowUserCss, $wgAllowUserJs;
562 $defaultPreferences['skin'] = array(
564 'options' => self
::generateSkinOptions( $user, $context ),
566 'section' => 'rendering/skin',
569 # Create links to user CSS/JS pages for all skins
570 # This code is basically copied from generateSkinOptions(). It'd
571 # be nice to somehow merge this back in there to avoid redundancy.
572 if ( $wgAllowUserCss ||
$wgAllowUserJs ) {
573 $linkTools = array();
574 $userName = $user->getName();
576 if ( $wgAllowUserCss ) {
577 $cssPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.css' );
578 $linkTools[] = Linker
::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
581 if ( $wgAllowUserJs ) {
582 $jsPage = Title
::makeTitleSafe( NS_USER
, $userName . '/common.js' );
583 $linkTools[] = Linker
::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
586 $defaultPreferences['commoncssjs'] = array(
589 'default' => $context->getLanguage()->pipeList( $linkTools ),
590 'label-message' => 'prefs-common-css-js',
591 'section' => 'rendering/skin',
598 * @param $context IContextSource
599 * @param $defaultPreferences Array
601 static function filesPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
602 ## Files #####################################
603 $defaultPreferences['imagesize'] = array(
605 'options' => self
::getImageSizes( $context ),
606 'label-message' => 'imagemaxsize',
607 'section' => 'rendering/files',
609 $defaultPreferences['thumbsize'] = array(
611 'options' => self
::getThumbSizes( $context ),
612 'label-message' => 'thumbsize',
613 'section' => 'rendering/files',
619 * @param $context IContextSource
620 * @param $defaultPreferences
623 static function datetimePreferences( $user, IContextSource
$context, &$defaultPreferences ) {
624 ## Date and time #####################################
625 $dateOptions = self
::getDateOptions( $context );
626 if ( $dateOptions ) {
627 $defaultPreferences['date'] = array(
629 'options' => $dateOptions,
631 'section' => 'datetime/dateformat',
636 $now = wfTimestampNow();
637 $lang = $context->getLanguage();
638 $nowlocal = Xml
::element( 'span', array( 'id' => 'wpLocalTime' ),
639 $lang->time( $now, true ) );
640 $nowserver = $lang->time( $now, false ) .
641 Html
::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 +
(int)substr( $now, 10, 2 ) );
643 $defaultPreferences['nowserver'] = array(
646 'label-message' => 'servertime',
647 'default' => $nowserver,
648 'section' => 'datetime/timeoffset',
651 $defaultPreferences['nowlocal'] = array(
654 'label-message' => 'localtime',
655 'default' => $nowlocal,
656 'section' => 'datetime/timeoffset',
659 // Grab existing pref.
660 $tzOffset = $user->getOption( 'timecorrection' );
661 $tz = explode( '|', $tzOffset, 3 );
663 $tzOptions = self
::getTimezoneOptions( $context );
665 $tzSetting = $tzOffset;
666 if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) {
668 $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) %
60 );
669 } elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' &&
670 !in_array( $tzOffset, HTMLFormField
::flattenOptions( $tzOptions ) ) )
672 # Timezone offset can vary with DST
673 $userTZ = timezone_open( $tz[2] );
674 if ( $userTZ !== false ) {
675 $minDiff = floor( timezone_offset_get( $userTZ, date_create( 'now' ) ) / 60 );
676 $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}";
680 $defaultPreferences['timecorrection'] = array(
681 'class' => 'HTMLSelectOrOtherField',
682 'label-message' => 'timezonelegend',
683 'options' => $tzOptions,
684 'default' => $tzSetting,
686 'section' => 'datetime/timeoffset',
692 * @param $context IContextSource
693 * @param $defaultPreferences Array
695 static function renderingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
696 ## Page Rendering ##############################
697 global $wgAllowUserCssPrefs;
698 if ( $wgAllowUserCssPrefs ) {
699 $defaultPreferences['underline'] = array(
702 $context->msg( 'underline-never' )->text() => 0,
703 $context->msg( 'underline-always' )->text() => 1,
704 $context->msg( 'underline-default' )->text() => 2,
706 'label-message' => 'tog-underline',
707 'section' => 'rendering/advancedrendering',
711 $stubThresholdValues = array( 50, 100, 500, 1000, 2000, 5000, 10000 );
712 $stubThresholdOptions = array( $context->msg( 'stub-threshold-disabled' )->text() => 0 );
713 foreach ( $stubThresholdValues as $value ) {
714 $stubThresholdOptions[$context->msg( 'size-bytes', $value )->text()] = $value;
717 $defaultPreferences['stubthreshold'] = array(
718 'type' => 'selectorother',
719 'section' => 'rendering/advancedrendering',
720 'options' => $stubThresholdOptions,
722 'label-raw' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay?
725 if ( $wgAllowUserCssPrefs ) {
726 $defaultPreferences['showtoc'] = array(
728 'section' => 'rendering/advancedrendering',
729 'label-message' => 'tog-showtoc',
732 $defaultPreferences['nocache'] = array(
734 'label-message' => 'tog-nocache',
735 'section' => 'rendering/advancedrendering',
737 $defaultPreferences['showhiddencats'] = array(
739 'section' => 'rendering/advancedrendering',
740 'label-message' => 'tog-showhiddencats'
743 if ( $wgAllowUserCssPrefs ) {
744 $defaultPreferences['justify'] = array(
746 'section' => 'rendering/advancedrendering',
747 'label-message' => 'tog-justify',
751 $defaultPreferences['numberheadings'] = array(
753 'section' => 'rendering/advancedrendering',
754 'label-message' => 'tog-numberheadings',
760 * @param $context IContextSource
761 * @param $defaultPreferences Array
763 static function editingPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
764 global $wgAllowUserCssPrefs;
766 ## Editing #####################################
767 if ( $wgAllowUserCssPrefs ) {
768 $defaultPreferences['editsection'] = array(
770 'section' => 'editing/advancedediting',
771 'label-message' => 'tog-editsection',
774 $defaultPreferences['editsectiononrightclick'] = array(
776 'section' => 'editing/advancedediting',
777 'label-message' => 'tog-editsectiononrightclick',
779 $defaultPreferences['editondblclick'] = array(
781 'section' => 'editing/advancedediting',
782 'label-message' => 'tog-editondblclick',
785 if ( $wgAllowUserCssPrefs ) {
786 $defaultPreferences['editfont'] = array(
788 'section' => 'editing/editor',
789 'label-message' => 'editfont-style',
791 $context->msg( 'editfont-default' )->text() => 'default',
792 $context->msg( 'editfont-monospace' )->text() => 'monospace',
793 $context->msg( 'editfont-sansserif' )->text() => 'sans-serif',
794 $context->msg( 'editfont-serif' )->text() => 'serif',
798 $defaultPreferences['cols'] = array(
800 'label-message' => 'columns',
801 'section' => 'editing/editor',
805 $defaultPreferences['rows'] = array(
807 'label-message' => 'rows',
808 'section' => 'editing/editor',
812 if ( $user->isAllowed( 'minoredit' ) ) {
813 $defaultPreferences['minordefault'] = array(
815 'section' => 'editing/editor',
816 'label-message' => 'tog-minordefault',
819 $defaultPreferences['forceeditsummary'] = array(
821 'section' => 'editing/editor',
822 'label-message' => 'tog-forceeditsummary',
824 $defaultPreferences['useeditwarning'] = array(
826 'section' => 'editing/editor',
827 'label-message' => 'tog-useeditwarning',
829 $defaultPreferences['showtoolbar'] = array(
831 'section' => 'editing/editor',
832 'label-message' => 'tog-showtoolbar',
835 $defaultPreferences['previewonfirst'] = array(
837 'section' => 'editing/preview',
838 'label-message' => 'tog-previewonfirst',
840 $defaultPreferences['previewontop'] = array(
842 'section' => 'editing/preview',
843 'label-message' => 'tog-previewontop',
845 $defaultPreferences['uselivepreview'] = array(
847 'section' => 'editing/preview',
848 'label-message' => 'tog-uselivepreview',
855 * @param $context IContextSource
856 * @param $defaultPreferences Array
858 static function rcPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
859 global $wgRCMaxAge, $wgRCShowWatchingUsers;
861 ## RecentChanges #####################################
862 $defaultPreferences['rcdays'] = array(
864 'label-message' => 'recentchangesdays',
865 'section' => 'rc/displayrc',
867 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ),
868 'help' => $context->msg( 'recentchangesdays-max' )->numParams(
869 ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )->text()
871 $defaultPreferences['rclimit'] = array(
873 'label-message' => 'recentchangescount',
874 'help-message' => 'prefs-help-recentchangescount',
875 'section' => 'rc/displayrc',
877 $defaultPreferences['usenewrc'] = array(
879 'label-message' => 'tog-usenewrc',
880 'section' => 'rc/advancedrc',
882 $defaultPreferences['hideminor'] = array(
884 'label-message' => 'tog-hideminor',
885 'section' => 'rc/advancedrc',
888 if ( $user->useRCPatrol() ) {
889 $defaultPreferences['hidepatrolled'] = array(
891 'section' => 'rc/advancedrc',
892 'label-message' => 'tog-hidepatrolled',
894 $defaultPreferences['newpageshidepatrolled'] = array(
896 'section' => 'rc/advancedrc',
897 'label-message' => 'tog-newpageshidepatrolled',
901 if ( $wgRCShowWatchingUsers ) {
902 $defaultPreferences['shownumberswatching'] = array(
904 'section' => 'rc/advancedrc',
905 'label-message' => 'tog-shownumberswatching',
912 * @param $context IContextSource
913 * @param $defaultPreferences
915 static function watchlistPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
916 global $wgUseRCPatrol, $wgEnableAPI, $wgRCMaxAge;
918 $watchlistdaysMax = ceil( $wgRCMaxAge / ( 3600 * 24 ) );
920 ## Watchlist #####################################
921 $defaultPreferences['watchlistdays'] = array(
924 'max' => $watchlistdaysMax,
925 'section' => 'watchlist/displaywatchlist',
926 'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams(
927 $watchlistdaysMax )->text(),
928 'label-message' => 'prefs-watchlist-days',
930 $defaultPreferences['wllimit'] = array(
934 'label-message' => 'prefs-watchlist-edits',
935 'help' => $context->msg( 'prefs-watchlist-edits-max' )->escaped(),
936 'section' => 'watchlist/displaywatchlist',
938 $defaultPreferences['extendwatchlist'] = array(
940 'section' => 'watchlist/advancedwatchlist',
941 'label-message' => 'tog-extendwatchlist',
943 $defaultPreferences['watchlisthideminor'] = array(
945 'section' => 'watchlist/advancedwatchlist',
946 'label-message' => 'tog-watchlisthideminor',
948 $defaultPreferences['watchlisthidebots'] = array(
950 'section' => 'watchlist/advancedwatchlist',
951 'label-message' => 'tog-watchlisthidebots',
953 $defaultPreferences['watchlisthideown'] = array(
955 'section' => 'watchlist/advancedwatchlist',
956 'label-message' => 'tog-watchlisthideown',
958 $defaultPreferences['watchlisthideanons'] = array(
960 'section' => 'watchlist/advancedwatchlist',
961 'label-message' => 'tog-watchlisthideanons',
963 $defaultPreferences['watchlisthideliu'] = array(
965 'section' => 'watchlist/advancedwatchlist',
966 'label-message' => 'tog-watchlisthideliu',
969 if ( $wgUseRCPatrol ) {
970 $defaultPreferences['watchlisthidepatrolled'] = array(
972 'section' => 'watchlist/advancedwatchlist',
973 'label-message' => 'tog-watchlisthidepatrolled',
978 'edit' => 'watchdefault',
979 'move' => 'watchmoves',
980 'delete' => 'watchdeletion'
984 if ( $user->isAllowed( 'createpage' ) ||
$user->isAllowed( 'createtalk' ) ) {
985 $watchTypes['read'] = 'watchcreations';
988 foreach ( $watchTypes as $action => $pref ) {
989 if ( $user->isAllowed( $action ) ) {
990 // Give grep a chance to find the usages:
991 // tog-watchdefault, tog-watchmoves, tog-watchdeletion, tog-watchcreations
992 $defaultPreferences[$pref] = array(
994 'section' => 'watchlist/advancedwatchlist',
995 'label-message' => "tog-$pref",
1000 if ( $wgEnableAPI ) {
1001 $defaultPreferences['watchlisttoken'] = array(
1004 $defaultPreferences['watchlisttoken-info'] = array(
1006 'section' => 'watchlist/tokenwatchlist',
1007 'label-message' => 'prefs-watchlist-token',
1008 'default' => $user->getTokenFromOption( 'watchlisttoken' ),
1009 'help-message' => 'prefs-help-watchlist-token2',
1016 * @param $context IContextSource
1017 * @param $defaultPreferences Array
1019 static function searchPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1020 global $wgContLang, $wgVectorUseSimpleSearch;
1022 ## Search #####################################
1023 $defaultPreferences['searchlimit'] = array(
1025 'label-message' => 'resultsperpage',
1026 'section' => 'searchoptions/displaysearchoptions',
1030 if ( $wgVectorUseSimpleSearch ) {
1031 $defaultPreferences['vector-simplesearch'] = array(
1033 'label-message' => 'vector-simplesearch-preference',
1034 'section' => 'searchoptions/displaysearchoptions',
1038 $defaultPreferences['disablesuggest'] = array(
1040 'label-message' => 'mwsuggest-disable',
1041 'section' => 'searchoptions/displaysearchoptions',
1044 $defaultPreferences['searcheverything'] = array(
1046 'label-message' => 'searcheverything-enable',
1047 'section' => 'searchoptions/advancedsearchoptions',
1050 $nsOptions = $wgContLang->getFormattedNamespaces();
1051 $nsOptions[0] = $context->msg( 'blanknamespace' )->text();
1052 foreach ( $nsOptions as $ns => $name ) {
1054 unset( $nsOptions[$ns] );
1058 $defaultPreferences['searchnamespaces'] = array(
1059 'type' => 'multiselect',
1060 'label-message' => 'defaultns',
1061 'options' => array_flip( $nsOptions ),
1062 'section' => 'searchoptions/advancedsearchoptions',
1063 'prefix' => 'searchNs',
1069 * @param $context IContextSource
1070 * @param $defaultPreferences Array
1072 static function miscPreferences( $user, IContextSource
$context, &$defaultPreferences ) {
1075 ## Misc #####################################
1076 $defaultPreferences['diffonly'] = array(
1078 'section' => 'misc/diffs',
1079 'label-message' => 'tog-diffonly',
1081 $defaultPreferences['norollbackdiff'] = array(
1083 'section' => 'misc/diffs',
1084 'label-message' => 'tog-norollbackdiff',
1087 // Stuff from Language::getExtraUserToggles()
1088 $toggles = $wgContLang->getExtraUserToggles();
1090 foreach ( $toggles as $toggle ) {
1091 $defaultPreferences[$toggle] = array(
1093 'section' => 'personal/i18n',
1094 'label-message' => "tog-$toggle",
1100 * @param $user User The User object
1101 * @param $context IContextSource
1102 * @return Array: text/links to display as key; $skinkey as value
1104 static function generateSkinOptions( $user, IContextSource
$context ) {
1105 global $wgDefaultSkin, $wgAllowUserCss, $wgAllowUserJs;
1108 $mptitle = Title
::newMainPage();
1109 $previewtext = $context->msg( 'skin-preview' )->text();
1111 # Only show members of Skin::getSkinNames() rather than
1112 # $skinNames (skins is all skin names from Language.php)
1113 $validSkinNames = Skin
::getUsableSkins();
1115 # Sort by UI skin name. First though need to update validSkinNames as sometimes
1116 # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI).
1117 foreach ( $validSkinNames as $skinkey => &$skinname ) {
1118 $msg = $context->msg( "skinname-{$skinkey}" );
1119 if ( $msg->exists() ) {
1120 $skinname = htmlspecialchars( $msg->text() );
1123 asort( $validSkinNames );
1125 foreach ( $validSkinNames as $skinkey => $sn ) {
1126 $linkTools = array();
1128 # Mark the default skin
1129 if ( $skinkey == $wgDefaultSkin ) {
1130 $linkTools[] = $context->msg( 'default' )->escaped();
1133 # Create preview link
1134 $mplink = htmlspecialchars( $mptitle->getLocalURL( array( 'useskin' => $skinkey ) ) );
1135 $linkTools[] = "<a target='_blank' href=\"$mplink\">$previewtext</a>";
1137 # Create links to user CSS/JS pages
1138 if ( $wgAllowUserCss ) {
1139 $cssPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.css' );
1140 $linkTools[] = Linker
::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() );
1143 if ( $wgAllowUserJs ) {
1144 $jsPage = Title
::makeTitleSafe( NS_USER
, $user->getName() . '/' . $skinkey . '.js' );
1145 $linkTools[] = Linker
::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() );
1148 $display = $sn . ' ' . $context->msg( 'parentheses', $context->getLanguage()->pipeList( $linkTools ) )->text();
1149 $ret[$display] = $skinkey;
1156 * @param $context IContextSource
1159 static function getDateOptions( IContextSource
$context ) {
1160 $lang = $context->getLanguage();
1161 $dateopts = $lang->getDatePreferences();
1166 if ( !in_array( 'default', $dateopts ) ) {
1167 $dateopts[] = 'default'; // Make sure default is always valid
1171 // KLUGE: site default might not be valid for user language
1172 global $wgDefaultUserOptions;
1173 if ( !in_array( $wgDefaultUserOptions['date'], $dateopts ) ) {
1174 $wgDefaultUserOptions['date'] = 'default';
1177 $epoch = wfTimestampNow();
1178 foreach ( $dateopts as $key ) {
1179 if ( $key == 'default' ) {
1180 $formatted = $context->msg( 'datedefault' )->escaped();
1182 $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) );
1184 $ret[$formatted] = $key;
1191 * @param $context IContextSource
1194 static function getImageSizes( IContextSource
$context ) {
1195 global $wgImageLimits;
1198 $pixels = $context->msg( 'unit-pixel' )->text();
1200 foreach ( $wgImageLimits as $index => $limits ) {
1201 $display = "{$limits[0]}×{$limits[1]}" . $pixels;
1202 $ret[$display] = $index;
1209 * @param $context IContextSource
1212 static function getThumbSizes( IContextSource
$context ) {
1213 global $wgThumbLimits;
1216 $pixels = $context->msg( 'unit-pixel' )->text();
1218 foreach ( $wgThumbLimits as $index => $size ) {
1219 $display = $size . $pixels;
1220 $ret[$display] = $index;
1227 * @param $signature string
1228 * @param $alldata array
1229 * @param $form HTMLForm
1230 * @return bool|string
1232 static function validateSignature( $signature, $alldata, $form ) {
1233 global $wgParser, $wgMaxSigChars;
1234 if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
1235 return Xml
::element( 'span', array( 'class' => 'error' ),
1236 $form->msg( 'badsiglength' )->numParams( $wgMaxSigChars )->text() );
1237 } elseif ( isset( $alldata['fancysig'] ) &&
1238 $alldata['fancysig'] &&
1239 false === $wgParser->validateSig( $signature ) ) {
1240 return Xml
::element( 'span', array( 'class' => 'error' ), $form->msg( 'badsig' )->text() );
1247 * @param $signature string
1248 * @param $alldata array
1249 * @param $form HTMLForm
1252 static function cleanSignature( $signature, $alldata, $form ) {
1253 if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
1255 $signature = $wgParser->cleanSig( $signature );
1257 // When no fancy sig used, make sure ~{3,5} get removed.
1258 $signature = Parser
::cleanSigInSig( $signature );
1266 * @param $context IContextSource
1267 * @param $formClass string
1268 * @param array $remove array of items to remove
1271 static function getFormObject( $user, IContextSource
$context, $formClass = 'PreferencesForm', array $remove = array() ) {
1272 $formDescriptor = Preferences
::getPreferences( $user, $context );
1273 if ( count( $remove ) ) {
1274 $removeKeys = array_flip( $remove );
1275 $formDescriptor = array_diff_key( $formDescriptor, $removeKeys );
1278 // Remove type=api preferences. They are not intended for rendering in the form.
1279 foreach ( $formDescriptor as $name => $info ) {
1280 if ( isset( $info['type'] ) && $info['type'] === 'api' ) {
1281 unset( $formDescriptor[$name] );
1286 * @var $htmlForm PreferencesForm
1288 $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
1290 $htmlForm->setModifiedUser( $user );
1291 $htmlForm->setId( 'mw-prefs-form' );
1292 $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() );
1293 # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save'
1294 $htmlForm->setSubmitTooltip( 'preferences-save' );
1295 $htmlForm->setSubmitID( 'prefsubmit' );
1296 $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) );
1302 * @param $context IContextSource
1305 static function getTimezoneOptions( IContextSource
$context ) {
1308 global $wgLocalTZoffset;
1309 $timestamp = MWTimestamp
::getLocalInstance();
1310 // Check that $wgLocalTZoffset is the same as the local time zone offset
1311 if ( $wgLocalTZoffset == $timestamp->format( 'Z' ) / 60 ) {
1312 $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $timestamp->getTimezone()->getName() )->text();
1314 $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) %
60 );
1315 $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text();
1317 $opt[$server_tz_msg] = "System|$wgLocalTZoffset";
1318 $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other';
1319 $opt[$context->msg( 'guesstimezone' )->text()] = 'guess';
1321 if ( function_exists( 'timezone_identifiers_list' ) ) {
1322 # Read timezone list
1323 $tzs = timezone_identifiers_list();
1326 $tzRegions = array();
1327 $tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text();
1328 $tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text();
1329 $tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text();
1330 $tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text();
1331 $tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text();
1332 $tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text();
1333 $tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text();
1334 $tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text();
1335 $tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text();
1336 $tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text();
1337 asort( $tzRegions );
1339 $prefill = array_fill_keys( array_values( $tzRegions ), array() );
1340 $opt = array_merge( $opt, $prefill );
1342 $now = date_create( 'now' );
1344 foreach ( $tzs as $tz ) {
1345 $z = explode( '/', $tz, 2 );
1347 # timezone_identifiers_list() returns a number of
1348 # backwards-compatibility entries. This filters them out of the
1349 # list presented to the user.
1350 if ( count( $z ) != 2 ||
!array_key_exists( $z[0], $tzRegions ) ) {
1355 $z[0] = $tzRegions[$z[0]];
1357 $minDiff = floor( timezone_offset_get( timezone_open( $tz ), $now ) / 60 );
1359 $display = str_replace( '_', ' ', $z[0] . '/' . $z[1] );
1360 $value = "ZoneInfo|$minDiff|$tz";
1362 $opt[$z[0]][$display] = $value;
1373 static function filterIntval( $value, $alldata ) {
1374 return intval( $value );
1382 static function filterTimezoneInput( $tz, $alldata ) {
1383 $data = explode( '|', $tz, 3 );
1384 switch ( $data[0] ) {
1389 $data = explode( ':', $tz, 2 );
1390 if ( count( $data ) == 2 ) {
1391 $data[0] = intval( $data[0] );
1392 $data[1] = intval( $data[1] );
1393 $minDiff = abs( $data[0] ) * 60 +
$data[1];
1394 if ( $data[0] < 0 ) {
1395 $minDiff = - $minDiff;
1398 $minDiff = intval( $data[0] ) * 60;
1401 # Max is +14:00 and min is -12:00, see:
1402 # http://en.wikipedia.org/wiki/Timezone
1403 $minDiff = min( $minDiff, 840 ); # 14:00
1404 $minDiff = max( $minDiff, - 720 ); # -12:00
1405 return 'Offset|' . $minDiff;
1410 * Handle the form submission if everything validated properly
1413 * @param $form PreferencesForm
1414 * @param $entryPoint string
1415 * @return bool|Status|string
1417 static function tryFormSubmit( $formData, $form, $entryPoint = 'internal' ) {
1418 global $wgHiddenPrefs, $wgAuth;
1420 $user = $form->getModifiedUser();
1423 if ( !$user->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1424 return Status
::newFatal( 'mypreferencesprotected' );
1428 foreach ( array_keys( $formData ) as $name ) {
1429 if ( isset( self
::$saveFilters[$name] ) ) {
1431 call_user_func( self
::$saveFilters[$name], $formData[$name], $formData );
1435 // Fortunately, the realname field is MUCH simpler
1436 // (not really "private", but still shouldn't be edited without permission)
1437 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->isAllowed( 'editmyprivateinfo' ) ) {
1438 $realName = $formData['realname'];
1439 $user->setRealName( $realName );
1442 if ( $user->isAllowed( 'editmyoptions' ) ) {
1443 foreach ( self
::$saveBlacklist as $b ) {
1444 unset( $formData[$b] );
1447 # If users have saved a value for a preference which has subsequently been disabled
1448 # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference
1449 # is subsequently re-enabled
1450 # TODO: maintenance script to actually delete these
1451 foreach ( $wgHiddenPrefs as $pref ) {
1452 # If the user has not set a non-default value here, the default will be returned
1453 # and subsequently discarded
1454 $formData[$pref] = $user->getOption( $pref, null, true );
1457 // Keep old preferences from interfering due to back-compat code, etc.
1458 $user->resetOptions( 'unused', $form->getContext() );
1460 foreach ( $formData as $key => $value ) {
1461 $user->setOption( $key, $value );
1464 $user->saveSettings();
1467 $wgAuth->updateExternalDB( $user );
1474 * @param $form PreferencesForm
1477 public static function tryUISubmit( $formData, $form ) {
1478 $res = self
::tryFormSubmit( $formData, $form, 'ui' );
1481 $urlOptions = array( 'success' => 1 );
1483 if ( $res === 'eauth' ) {
1484 $urlOptions['eauth'] = 1;
1487 $urlOptions +
= $form->getExtraSuccessRedirectParameters();
1489 $url = $form->getTitle()->getFullURL( $urlOptions );
1491 $form->getContext()->getOutput()->redirect( $url );
1494 return Status
::newGood();
1498 * Try to set a user's email address.
1499 * This does *not* try to validate the address.
1500 * Caller is responsible for checking $wgAuth and 'editmyprivateinfo'
1503 * @deprecated in 1.20; use User::setEmailWithConfirmation() instead.
1505 * @param string $newaddr New email address
1506 * @return Array (true on success or Status on failure, info string)
1508 public static function trySetUserEmail( User
$user, $newaddr ) {
1509 wfDeprecated( __METHOD__
, '1.20' );
1511 $result = $user->setEmailWithConfirmation( $newaddr );
1512 if ( $result->isGood() ) {
1513 return array( true, $result->value
);
1515 return array( $result, 'mailerror' );
1520 * @deprecated in 1.19
1524 public static function loadOldSearchNs( $user ) {
1525 wfDeprecated( __METHOD__
, '1.19' );
1527 $searchableNamespaces = SearchEngine
::searchableNamespaces();
1528 // Back compat with old format
1531 foreach ( $searchableNamespaces as $ns => $name ) {
1532 if ( $user->getOption( 'searchNs' . $ns ) ) {
1541 /** Some tweaks to allow js prefs to work */
1542 class PreferencesForm
extends HTMLForm
{
1543 // Override default value from HTMLForm
1544 protected $mSubSectionBeforeFields = false;
1546 private $modifiedUser;
1551 public function setModifiedUser( $user ) {
1552 $this->modifiedUser
= $user;
1558 public function getModifiedUser() {
1559 if ( $this->modifiedUser
=== null ) {
1560 return $this->getUser();
1562 return $this->modifiedUser
;
1567 * Get extra parameters for the query string when redirecting after
1572 public function getExtraSuccessRedirectParameters() {
1577 * @param $html string
1580 function wrapForm( $html ) {
1581 $html = Xml
::tags( 'div', array( 'id' => 'preferences' ), $html );
1583 return parent
::wrapForm( $html );
1589 function getButtons() {
1590 if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
1594 $html = parent
::getButtons();
1596 if ( $this->getModifiedUser()->isAllowed( 'editmyoptions' ) ) {
1597 $t = SpecialPage
::getTitleFor( 'Preferences', 'reset' );
1599 $html .= "\n" . Linker
::link( $t, $this->msg( 'restoreprefs' )->escaped() );
1601 $html = Xml
::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html );
1608 * Separate multi-option preferences into multiple preferences, since we
1609 * have to store them separately
1610 * @param $data array
1613 function filterDataForSubmit( $data ) {
1614 foreach ( $this->mFlatFields
as $fieldname => $field ) {
1615 if ( $field instanceof HTMLNestedFilterable
) {
1616 $info = $field->mParams
;
1617 $prefix = isset( $info['prefix'] ) ?
$info['prefix'] : $fieldname;
1618 foreach ( $field->filterDataForSubmit( $data[$fieldname] ) as $key => $value ) {
1619 $data["$prefix$key"] = $value;
1621 unset( $data[$fieldname] );
1629 * Get the whole body of the form.
1632 function getBody() {
1633 return $this->displaySection( $this->mFieldTree
, '', 'mw-prefsection-' );
1637 * Get the "<legend>" for a given section key. Normally this is the
1638 * prefs-$key message but we'll allow extensions to override it.
1639 * @param $key string
1642 function getLegend( $key ) {
1643 $legend = parent
::getLegend( $key );
1644 wfRunHooks( 'PreferencesGetLegend', array( $this, $key, &$legend ) );